{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87142eac",
   "metadata": {},
   "outputs": [],
   "source": [
    "# imports\n",
    "\n",
    "import os\n",
    "import requests\n",
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from IPython.display import Markdown, display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b04cebfd",
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "openai_api_key = os.getenv('OPENAI_API_KEY')\n",
    "anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
    "google_api_key = os.getenv('GOOGLE_API_KEY')\n",
    "\n",
    "if openai_api_key:\n",
    "    print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
    "else:\n",
    "    print(\"OpenAI API Key not set\")\n",
    "    \n",
    "if anthropic_api_key:\n",
    "    print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
    "else:\n",
    "    print(\"Anthropic API Key not set (and this is optional)\")\n",
    "\n",
    "if google_api_key:\n",
    "    print(f\"Google API Key exists and begins {google_api_key[:2]}\")\n",
    "else:\n",
    "    print(\"Google API Key not set (and this is optional)\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89cc40e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "openai = OpenAI()\n",
    "\n",
    "\n",
    "anthropic_url = \"https://api.anthropic.com/v1/\"\n",
    "gemini_url = \"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
    "\n",
    "anthropic = OpenAI(api_key=anthropic_api_key, base_url=anthropic_url)\n",
    "gemini = OpenAI(api_key=google_api_key, base_url=gemini_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "129d9cbf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Let's make a conversation between GPT-4.1-mini and Claude-3.5-haiku\n",
    "# We're using cheap versions of models so the costs will be minimal\n",
    "\n",
    "gpt_model = \"gpt-4.1-mini\"\n",
    "claude_model = \"claude-3-5-haiku-latest\"\n",
    "gemini_model = \"gemini-2.5-flash\"\n",
    "\n",
    "gpt_system = \"You are the one who loves football \\\n",
    "    defend your sports among two other chatbots.\"\n",
    "\n",
    "claude_system = \"You are the one who loves basketball \\\n",
    "    defend your sports among two other chatbots.\"\n",
    "\n",
    "gemini_system = \"You are the one who loves cricket \\\n",
    "    defend your sports among two other chatbots.\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f8eabfe",
   "metadata": {},
   "outputs": [],
   "source": [
    "conversation = []\n",
    "\n",
    "def complete_conversation():\n",
    "    return \"\\n\".join(conversation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dccfc1e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def alex():\n",
    "    user_prompt= f\"\"\"You are alex and you are in conversation with blake and charlie. \\\n",
    "                {complete_conversation()} \\\n",
    "                Here is the conversation till now \\\n",
    "                Now continue with the conversation further.\"\"\"\n",
    "    return user_prompt\n",
    "\n",
    "def blake():\n",
    "    user_prompt= f\"\"\"You are blake and you are in conversation with alex and charlie. \\\n",
    "                {complete_conversation()} \\\n",
    "                Here is the conversation till now \\\n",
    "                Now continue with the conversation further.\"\"\"\n",
    "    return user_prompt\n",
    "\n",
    "def charlie():\n",
    "    user_prompt= f\"\"\"You are charlie and you are in conversation with alex and blake. \\\n",
    "                {complete_conversation()} \\\n",
    "                Here is the conversation till now \\\n",
    "                Now continue with the conversation further.\"\"\"\n",
    "    return user_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f943baf0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def alex_speaks():\n",
    "    res = openai.chat.completions.create(\n",
    "        model=gpt_model,\n",
    "        messages=[\n",
    "            {\"role\":\"system\", \"content\": gpt_system},\n",
    "            {\"role\":\"user\", \"content\": alex()}\n",
    "        ]\n",
    "    )\n",
    "    return res.choices[0].message.content\n",
    "\n",
    "def blake_speaks():\n",
    "    res = anthropic.chat.completions.create(\n",
    "        model=claude_model,\n",
    "        messages=[\n",
    "            {\"role\":\"system\", \"content\": claude_system},\n",
    "            {\"role\":\"user\", \"content\": blake()}\n",
    "        ]\n",
    "    )\n",
    "    return res.choices[0].message.content\n",
    "\n",
    "def charlie_speaks():\n",
    "    res = gemini.chat.completions.create(\n",
    "        model=gemini_model,\n",
    "        messages=[\n",
    "            {\"role\":\"system\", \"content\": gemini_system},\n",
    "            {\"role\":\"user\", \"content\": charlie()}\n",
    "        ]\n",
    "    )\n",
    "    return res.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d71d6ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(1):\n",
    "    alex_res = alex_speaks()\n",
    "    print(f\"Alex: \\n {alex_res}\")\n",
    "    conversation.append(f\"Alex: {alex_res}\")\n",
    "\n",
    "    blake_res = blake_speaks()\n",
    "    print(f\"Blake: \\n {blake_res}\")\n",
    "    conversation.append(f\"Blake: {blake_res}\")\n",
    "\n",
    "    charlie_res = charlie_speaks()\n",
    "    print(f\"Charlie: \\n {charlie_res}\")\n",
    "    conversation.append(f\"Charlie: {charlie_res}\")\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
